package com.example.design.a.factory;

import com.example.design.a.factory.domain.Product;
import com.example.design.a.factory.domain.ProductTypeEnum;
import org.thymeleaf.util.StringUtils;

/**
 * 抽象工厂模式
 * 制造汽车工厂
 * 可以增加产品族, 但不适合增加产品
 */
public abstract class AbstractFactory {
    /**
     * 获取建造工厂
     *
     * @param factoryString
     *
     * @return
     */
    public static AbstractFactory getFactory(String factoryString) {
        if (StringUtils.isEmpty(factoryString)) {
            return null;
        }
        switch (factoryString) {
            case "benz":
                return new BenzFactory();
            case "bmw":
                return new BmwFactory();
            case "haval":
                return new HavalFactory();
            case "audi":
                return new AudiFactory();
            case "huawei":
                return new HuaweiMobileFactory();
            default:
        }
        return null;
    }

    /**
     * 建造产品方法
     */
    public abstract Product build(ProductTypeEnum productType);
}
